---------------------------------------------------------------
File name   :  vv_ahblite_coverage.e
Title       :  Coverage
Project     :  vv_ahblite UVC
Developers  :  stefan,filip
Created     :  29.07.2011.
Description :  This file implements the optional coverage collection.
Notes       :  Coverage collection is an extension of the bus and
    :  agent monitor units.
---------------------------------------------------------------
Copyright  (c)2011
---------------------------------------------------------------

<'
package vv_ahblite;
 
-- ==========================================================================
-- Collect coverage per-bus basis.
-- ==========================================================================
extend has_coverage vv_ahblite_bus_monitor {
--------------------------------------------------------------------------
    -- Use this section to modify the example coverage definitions and add
    -- new coverage definitions.
    -- To do so edit the following coverage group example and add new
    -- cover groups:

    
    -- **********************************************************************

};

-- ==========================================================================
-- Collect coverage for transactions on a per-agent basis.
-- ==========================================================================

extend has_coverage vv_ahblite_master_monitor {
     
    -- **********************************************************************
    -- IVB-NOTE : OPTIONAL : Agent monitor coverage : 06 Coverage
    -- ----------------------------------------------------------------------
    -- Use this section to modify the example coverage definitions and add
    -- new coverage definitions.
    -- To do so edit the following coverage group example and add new cover
    -- groups:
	
	-- Sampling event for master coverage of bursts.
	event burst_end_master_cover is @burst_end;
	-- Sampling event for master coverage of transfer
	event transfer_end_master_cover is @transfer_end;
	--
	event trans_change_cover is @trans_change;
	------------------------------------------------------------------------
	-- Coverage for transitions of h_trans during wait state (H_READY = 0)
	-- IDLE -> NONSEQ while H_READY=0
	-- BUSY -> SEQ in a fixed length burst
	-- BUSY -> NONSEQ in a non fixed length burst
	cover trans_change using
		text = "H_TRANS changed during wait state" is{
		--transfer kind, item is used only for transition
//	    item agent_name using per_instance, 
//			text = "Current master name.", 
//			when = agent_name == M0;
			
			
		item burst: vv_ahblite_burst_t = previous_transaction.burst using
			text = "Previous burst kind.";	
		item transfer: vv_ahblite_transfer_t = transaction.transfer using 
			text = "Transfer kind.";
		item last_transfer: vv_ahblite_transfer_t = previous_transaction.transfer using
			text = "Previous transfer kind.";
		
		
		-- Transition of H_TRANS signal
		cross transfer, last_transfer, burst using 
			text = "Transition of H_TRANS signal during wait state",
			ignore = (not (last_transfer == BUSY and transfer == SEQ and burst not in [INCR, SINGLE]));
			
			--(not (last_transfer == IDLE and transfer == NONSEQ)) or 
			--(not (last_transfer == BUSY and transfer == NONSEQ and burst  in [INCR, SINGLE])) or
	};
//	------------------------------------------------------------------
	----------------------------------------------------------------
	-- Coverage of bursts
	cover burst_end_master_cover using
		text = " Burst coverage group. Sampled when burst ends" is{
			
//		item agent_name using per_instance, 
//			text = "Current master name.", 
//			when = agent_name == M0;
		
		item burst: vv_ahblite_burst_t = last_transfer.burst using
			text = "Burst kind (H_BURST)";
		item write_op: bit = last_transfer.write_op using 
			text = "Burst kind (H_BURST)";
		item data_size: vv_ahblite_data_size_t = last_transfer.data_size using
			text = "Burst kind (H_BURST)";
	    ---------------------------------------------------
		-- Cross item for most importan fields for a burst
		cross burst, write_op, data_size using
			text = "Cross coverage of burst fields";
		
		--item locked : bit = last_transfer.locked using
		--	text = "Locked state (H_LOCK)";
		--item protect: uint = last_transfer.protect using
		--	text = "Protected state (H_PROT)";
			
		-- Slave response for last transfer in a burst (H_RESP)
		item last_response: bit = transaction.response using 
			text = "Slave response for last transfer in a burst (H_RESP)";
		
		item last_transfer_kind: vv_ahblite_transfer_t = last_transfer.transfer using 
			text = "Transfer kind of last transfer in a burst. Ignore IDLE",
			ignore = (last_transfer_kind == IDLE);
		---------------------------------------------------
		-- Cross item all responses for all transfer kinds	
		cross burst, last_response, last_transfer_kind using 
			text = "Cross coverage for H_BURST, H_RESP and H_TRANS",
			illegal =
				-- Single transfer must finish with NONSEQ
				(burst == SINGLE and last_transfer_kind != NONSEQ) or
				-- if not single or incr and temination is OK then last trensfer mustn't be NONSEQ or busy
				(burst not in [SINGLE, INCR] and last_response == 0 and last_transfer_kind in [NONSEQ,BUSY]);
				-- MAYBE @@@@@@
		item num_of_busy: uint = busy_num using 
			text = "Number of busy transfers in burst", 
			ranges = {range([0..9],"",2); range([10..MAX_UINT])};
		
		item num_of_waits: uint = wait_states_num using 
			text = "Number of wait states (H_READY=0, H_RESP=0) in burst", 
			ranges = {range([0..10],"",2); range([11..16])};
			
		-- lower part of burst address
		item address_low: uint(bits:10) = last_transfer.addr % 1K using
			text = "Last address of burst % 1K", 
			ranges = {
				range([0..100]);
				range([101..1K-102]);
				range([1K-101..1K-1]);
			};
		---------------------------------------------------
		--Cross item for burst kind, data_size and address
		cross address_low, burst, data_size using 
			text = "Cross coverage for address, burst kind and data size";
			
		-- transitions of important signals
		transition burst using
			text = "H_BURST trasition";
		transition write_op using
			text = "WRITE_OP trasition";
		transition last_response using
			text = "Response of last transfer trasition";
		
	};
	--------------------------------------------------------------------
	-- Coverage of transactions
	cover transfer_end_master_cover using
			text = "Basic transaction coverage group. Collected when transfer end (reaches data phase)" is{
				
//		item agent_name using per_instance, 	
//			text = "Current master name.", 
//			when = agent_name == M0;
			
		--Transfer kind			
		item transfer: vv_ahblite_transfer_t = last_transfer.transfer using
			text = "Transfer kind (H_TRANS)";
		transition transfer using 
			text  = "Transition of H_TRANS signal (BUSY->SEQ, NONSEQ->SEQ...)", 
			ignore = prev_transfer == IDLE and transfer in [SEQ, BUSY];
		
		-- transfer response
		item response: bit= transaction.response using 
			text = "Transfer response (H_RASP)";
		-- cross HTRANS, HRESP - ignore error responnse after busy or idle
		cross transfer, response using
			text = "Cross coverage HTRANS and HRESP. If HTRANS in [busy, idle] HRESP must be OKAY", 
			ignore = transfer in [BUSY, IDLE] and response==1;
		-- address	
		item addr: vv_ahblite_addr_t = transaction.addr 
			using 	at_least = 100,
					ranges = {
						range([0..32767]);
						range([32768..65535]);
			};
			
//		item burst: vv_ahblite_burst_t = transaction.burst;
//		item data_size: vv_ahblite_data_size_t=transaction.data_size;
//		item write_op: bit= transaction.write_op;
//		
//		item ready: bit= transaction.ready;
	
	};
    -- **********************************************************************  
};

extend has_coverage vv_ahblite_slave_monitor {
     
    -- **********************************************************************
    -- IVB-NOTE : OPTIONAL : Agent monitor coverage : 06 Coverage
    -- ----------------------------------------------------------------------
    -- Use this section to modify the example coverage definitions and add
    -- new coverage definitions.
    -- To do so edit the following coverage group example and add new cover
    -- groups:
	
		-- Sampling event for slave coverage of bursts.
	event burst_end_slave_cover is @burst_end;
	-- Sampling event for slave coverage of transfer
	event transfer_end_slave_cover is @transfer_end;
	--
//	------------------------------------------------------------------
	----------------------------------------------------------------
	-- Coverage of bursts
	cover burst_end_slave_cover using
		text = " Burst coverage group. Sampled when burst ends" is{
			
//		item agent_name using per_instance, 
//			text = "Current slave name.", 
//			when = agent_name == M0;
		
		item burst: vv_ahblite_burst_t = last_transfer.burst using
			text = "Burst kind (H_BURST)";
		item write_op: bit = last_transfer.write_op using 
			text = "Burst kind (H_BURST)";
		item data_size: vv_ahblite_data_size_t = last_transfer.data_size using
			text = "Burst kind (H_BURST)";
	    ---------------------------------------------------
		-- Cross item for most importan fields for a burst
		cross burst, write_op, data_size using
			text = "Cross coverage of burst fields";
		
		--item locked : bit = last_transfer.locked using
		--	text = "Locked state (H_LOCK)";
		--item protect: uint = last_transfer.protect using
		--	text = "Protected state (H_PROT)";
			
		-- Slave response for last transfer in a burst (H_RESP)
		item last_response: bit = transaction.response using 
			text = "Slave response for last transfer in a burst (H_RESP)";
		
		item last_transfer_kind: vv_ahblite_transfer_t = last_transfer.transfer using 
			text = "Transfer kind of last transfer in a burst. Ignore IDLE",
			ignore = (last_transfer_kind == IDLE);
		---------------------------------------------------
		-- Cross item all responses for all transfer kinds	
		cross burst, last_response, last_transfer_kind using 
			text = "Cross coverage for H_BURST, H_RESP and H_TRANS",
			illegal =
				-- Single transfer must finish with NONSEQ
				(burst == SINGLE and last_transfer_kind != NONSEQ) or
				-- if not single or incr and temination is OK then last trensfer mustn't be NONSEQ or busy
				(burst not in [SINGLE, INCR] and last_response == 0 and last_transfer_kind in [NONSEQ,BUSY]);
				-- MAYBE @@@@@@
		item num_of_busy: uint = busy_num using 
			text = "Number of busy transfers in burst", 
			ranges = {range([0..10],"",2); range([11..MAX_UINT])};
		
		item num_of_waits: uint = wait_states_num using 
			text = "Number of wait states (H_READY=0, H_RESP=0) in burst", 
			ranges = {range([0..10],"",2); range([11..16])};
			
		-- lower part of burst address
		item address_low: uint(bits:10) = last_transfer.addr % 1K using
			text = "Last address of burst % 1K", 
			ranges = {
				range([0..100]);
				range([101..1K-102]);
				range([1K-101..1K-1]);
			};
		---------------------------------------------------
		--Cross item for burst kind, data_size and address
		cross address_low, burst, data_size using 
			text = "Cross coverage for address, burst kind and data size";
			
		-- transitions of important signals
		transition burst using
			text = "H_BURST trasition";
		transition write_op using
			text = "WRITE_OP trasition";
		transition last_response using
			text = "Response of last transfer trasition";
		
	};
	--------------------------------------------------------------------
	-- Coverage of transactions
	cover transfer_end_slave_cover using
			text = "Basic transaction coverage group. Collected when transfer end (reaches data phase)" is{
				
//		item agent_name using per_instance, 	
//			text = "Current slave name.", 
//			when = agent_name == M0;
			
		--Transfer kind			
		item transfer: vv_ahblite_transfer_t = last_transfer.transfer using
			text = "Transfer kind (H_TRANS)";
		transition transfer using 
			text  = "Transition of H_TRANS signal (BUSY->SEQ, NONSEQ->SEQ...)", 
			ignore = prev_transfer == IDLE and transfer in [SEQ, BUSY];
		
		-- transfer response
		item response: bit= transaction.response using 
			text = "Transfer response (H_RASP)";
		-- cross HTRANS, HRESP - ignore error responnse after busy or idle
		cross transfer, response using
			text = "Cross coverage HTRANS and HRESP. If HTRANS in [busy, idle] HRESP must be OKAY", 
			ignore = transfer in [BUSY, IDLE] and response==1;
		-- address	
//		item addr: vv_ahblite_addr_t = transaction.addr 
//			using 	at_least = 100,
//					ranges = {
//						range([0..32767]);
//						range([32768..65535]);
//			};
//			
//		item burst: vv_ahblite_burst_t = transaction.burst;
//		item data_size: vv_ahblite_data_size_t=transaction.data_size;
//		item write_op: bit= transaction.write_op;
//		
//		item ready: bit= transaction.ready;
	
	};
    -- **********************************************************************  
};
'>
